#include "StdAfx.h"
#include "FFSettingInterface.h"



COptionParameter::COptionParameter(void)
	:	m_nAudioSampleRate(44100)
	,	m_nAudioBitRate(128000)
	,	m_nAudioChannels(2)
	,	m_nFrameRate(25)
	,	m_nFrameRateBase(1)
	,	m_nFrameWidth(352)
	,	m_nFrameHeight(288)	
	,	m_nVideoBitRate(400*1000), m_nVideoBitRateTolerance(4000*1000)
	,   m_nGopSize(12)
	,	m_FramePixFmt(PIX_FMT_YUV420P)	
	,   m_videoCodecID(CODEC_ID_MPEG1VIDEO)
	,   m_audioCodecID(CODEC_ID_MP2)	
	,	m_eType(MPEG1)
	,   format("mpeg")
	,	ext(".mpg")
{
}


COptionParameter::~COptionParameter()
{
}

#define  AddToVector(p) \
	if(p){  \
	m_vecOption.push_back(p);\
	}\



CProfileManager::CProfileManager()
{
	COptionParameter* p0  = AddDefaultProfile();
	AddToVector(p0);
	COptionParameter* p1 = Add3gppProfile();
	AddToVector(p1);
	COptionParameter* p2 = AddIpodProfile();
	AddToVector(p2);
	COptionParameter* p3 = AddDvd();
	AddToVector(p3);
}


CProfileManager::~CProfileManager()
{
	vector<COptionParameter*>::iterator it;
	for (it = m_vecOption.begin(); it < m_vecOption.end(); it++)
	{
		COptionParameter* p = *it;
		delete p;
	}
	m_vecOption.clear();
}

int CProfileManager::GetProfileCount()
{
	return (int) m_vecOption.size();
}

COptionParameter* CProfileManager::GetProfile(int idx)
{
	if(m_vecOption.empty()) return NULL;
	if( idx >= (int)m_vecOption.size()) return NULL;
	return *(m_vecOption.begin() + idx);


}

COptionParameter* CProfileManager::GetProfile(PROFILE_TYPE etype)
{
	if(m_vecOption.empty()) return NULL;
	vector<COptionParameter*>::iterator it;
	for (it = m_vecOption.begin(); it < m_vecOption.end(); it++)
	{
		COptionParameter* para = *it;
		if(para->m_eType == etype)
			return para;
	}
	return NULL; 
}

void CProfileManager::clearProfiles()
{
	if(m_vecOption.empty()) return;
	for (vector<COptionParameter*>::iterator it = m_vecOption.begin(); 
		it < m_vecOption.end();it++)
	{
		COptionParameter* p = *it;
		delete p;
	}
	m_vecOption.clear();
}

COptionParameter* CProfileManager::Add3gppProfile()
{
	//ffmpeg -i Ev.mpg -acodec amr_nb -ar 8000 -ac 1 -ab 32 -vcodec h263 -s qcif -r 10 Ev.3gp

	COptionParameter* p = new COptionParameter;
	if(!p) return NULL;
	//p->m_strProfileName = "3gp";
	p->format = "3gp";
	p->ext = ".3gp";
	p->m_nAudioChannels = 1;
	p->m_nAudioSampleRate = 8000;
	p->m_audioCodecID = CODEC_ID_AMR_NB ;
	p->m_nAudioBitRate = 32000;
	

	p->m_videoCodecID = CODEC_ID_H263;
	p->m_nFrameWidth = 176;
	p->m_nFrameHeight = 144;//QCIF
	p->m_nFrameRate = 10;
	p->m_nFrameRateBase = 1;
	p->m_nVideoBitRate = 200000;

	p->m_eType =  QCIF_3GP;
	return p;
}

COptionParameter* CProfileManager::AddDvd()
{
	COptionParameter* p = new COptionParameter;
	if(!p)return NULL;
	p->format = "dvd";
	p->ext = ".mpg";
	p->m_nAudioChannels = 2;
	p->m_nAudioSampleRate = 48000;
	p->m_audioCodecID = CODEC_ID_AC3 ;
	p->m_nAudioBitRate = 128000;


	p->m_videoCodecID = CODEC_ID_MPEG2VIDEO;
	p->m_nFrameWidth = 720;
	p->m_nFrameHeight = 480;//QCIF
	p->m_nFrameRate = 25;
	p->m_nFrameRateBase = 1;
	p->m_nVideoBitRate = 600000;

	p->m_eType =  DVD_AC3;
	return p;

};

COptionParameter* CProfileManager::AddIpodProfile()
{
	//ffmpeg.exe -y -i "F:\media\video\lake.mpg" -f mp4 -title "lake" -timestamp "2007-06-20 10:23:21" 
	//-vcodec h264 -level 13 -b 768k -bt 768k -bufsize 2000k -maxrate 768k -g 250 -coder 0 //
	//-acodec aac -ac 2 -ab 128k 
	//"F:\doc\Converted Videos\iPod\H264\lake.mp4"

	COptionParameter* p = new COptionParameter;
	if(!p) return NULL;

	p->format = "mp4";
	p->ext    = ".mp4";
	p->m_videoCodecID = CODEC_ID_MPEG4;	
	p->m_nVideoBitRate = 400000;
	//p->m_nVideoBitRateTolerance = 4000*1000;
	//p->m_nVideoRcBufferSize = 2000*8*1024;
	//p->m_nVideoRcMaxRate = 768*1000;
	p->m_nFrameWidth = 352;
	p->m_nFrameHeight = 288;
	p->m_nGopSize = 12;
	p->m_nFrameRateBase = 1;
	p->m_nFrameRate = 25;

	p->m_audioCodecID = CODEC_ID_AAC;
	p->m_nAudioChannels = 2;
	p->m_nAudioBitRate = 128000;
	p->m_nAudioSampleRate = 44100;
	p->m_eType =  IPOD;

	return p;
}

COptionParameter* CProfileManager::AddDefaultProfile()
{
	COptionParameter* p = new COptionParameter;
	if(!p) return NULL;
	return p;
}

COptionParameter* CProfileManager::AddPspProfile()
{

   //	ffmpeg.exe -y -i "F:\media\video\lake.mpg" -bitexact -acodec mp3 -ac 2 -ar 44100 -vol 256 -ab 128 -f mp3 "C:\Program Files\VideoraPMPConverter\Videos\lake.mp3" -vcodec xvid -s 480x272 -b 768 -an -f avi "C:\Program Files\VideoraPMPConverter\Videos\lake.avi" 
	//  ffmpeg.exe -y -i "F:\media\video\chicken.avs" -bitexact -vcodec xvid -s 480x272 -b 768 -acodec mp3 -ac 2 -ar 44100 -vol 256 -ab 128 -f avi -pass 1 -passlogfile "C:\Program Files\VideoraPMPConverter\Videos\chicken" nul -f mp3 "C:\Program Files\VideoraPMPConverter\Videos\chicken.mp3" 
	COptionParameter* p = new COptionParameter;
	if(!p) return NULL;
	return p;

	//p->m_videoCodecID
}

